<template>
  <h1>猜数字练习</h1>
  <input type="text" v-model="num" placeholder="请输入数字">
  <button @click="guess">猜一猜</button>
  <h4>结果：{{res}}</h4>
</template>


<script setup>
import {ref} from "vue";
const num = ref('');
const res = ref('');
let guessNum = parseInt(Math.random()*100)+1;
console.log("作弊："+guessNum);
const guess = ()=>{
  let n = parseInt(num.value);
  if(isNaN(n)){
    alert("请输入数字");
  }else if(n>guessNum){
    res.value = "猜大了";
  }else if(n<guessNum){
    res.value = "猜小了";
  }else {
    res.value = "猜对了";
  }
}
</script>


<style scoped>

</style>